import 'package:flutter/material.dart';

class MyDialogWidget {
  static StatelessWidget showInputDialog(
      BuildContext context, String title, String value, String hintText,
      [Function? confim]) {
    return AlertDialog(
      title: Text(title),
      content: TextField(
        controller:
            TextEditingController.fromValue(TextEditingValue(text: value)),
        onChanged: (v) => {value = v},
        decoration: InputDecoration(
          hintText: hintText,
        ),
      ),
      actions: [
        TextButton(
          child: const Text("取消"),
          onPressed: () {
            Navigator.of(context).pop(false);
          },
        ),
        TextButton(
          child: const Text("确定"),
          onPressed: () {
            //关闭 返回true
            confim!(value);
            Navigator.of(context).pop(true);
          },
        ),
      ],
    );
  }

  static StatelessWidget showListDialog(
      BuildContext context, List<String> list,
      [Function? confim]) {
    return SimpleDialog(
      children: List.generate(
          list.length,
          (index) => SimpleDialogOption(
                onPressed: () {
                  confim!(list[index]);
                  Navigator.of(context).pop(true);
                },
                child: Text(list[index]),
              )),
    );
  }
}
